﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace FeiYang
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class 挂机面板_ : UserControl
    {
        public EventHandler 左角色被选择;
        public EventHandler 右角色被选择;
        public 挂机面板_()
        {
            InitializeComponent();
            if (!this.特殊挂机.IsChecked.HasValue || this.特殊挂机.IsChecked.Value == false)
            {
                this.特殊挂机分组.IsEnabled = false;
            }
            var 地图名称组 = new string[] { "小黑屋", "跃马大平原", "魔界角斗场","炼狱魔境一层", "炼狱魔境二层", "炼狱魔境三层", "铁血魔城",
                "地下魔域一层", "地下魔域二层", "地下魔域三层", "地下魔域四层", "地下魔域五层", "地下魔域六层_1",
                "矿区入口", "将军坟东一层", "将军坟东二层", "将军坟一层", "机关支路一", "地穴入口", "环道", "逆魔古刹一层", "逆魔古刹二层", "禁地之门", "一手遮天", "魔隐村", "深海密道一层" };

            foreach (var s in 地图名称组)
            {
                this.挂机地图下拉框.Items.Add(s);
            }
            this.挂机地图下拉框.Text = "铁血魔城";

            var 技能名称组 = new string[] { "无", "雷电术", "冰箭术", "狂龙紫电", "抗拒火环", "火墙", "冰咆哮", "冰旋风", "化身蝙蝠", "诱惑之光", "施毒术", "诅咒术", "治疗术", "群体治疗术", "幽冥火咒", "灵魂道符", "集体隐身术", "隐身术", "替身法符", "狮子吼", "召唤神兽", "强化骷髅术", "心灵召唤", "遁地" };
            foreach (var s in 技能名称组)
            {
                this.F1.Items.Add(s);
                this.F2.Items.Add(s);
                this.F3.Items.Add(s);
                this.F4.Items.Add(s);
                this.F5.Items.Add(s);
                this.F6.Items.Add(s);
                this.F7.Items.Add(s);
                this.F8.Items.Add(s);
            }
            this.F1.Text = "无";
            this.F2.Text = "无";
            this.F3.Text = "无";
            this.F4.Text = "无";
            this.F5.Text = "无";
            this.F6.Text = "无";
            this.F7.Text = "无";
            this.F8.Text = "无";
        }

        private void 特殊挂机_Checked(object sender, RoutedEventArgs e)
        {
            this.非特殊挂机分组.IsEnabled = false;
            this.expander1.IsExpanded = false;
            this.expander2.IsExpanded = false;
            this.expander3.IsExpanded = false;
            this.expander4.IsExpanded = false;
            this.expander4.IsEnabled = false;
            this.expander7.IsExpanded = false;
            this.expander7.IsEnabled = false;
            this.特殊挂机分组.IsEnabled = true;
            this.expander8.IsExpanded = true;
            this.包裹监测间隔输入框.IsEnabled = false;
            this.包裹监测间隔标签.IsEnabled = false;
        }

        private void 特殊挂机_Unchecked(object sender, RoutedEventArgs e)
        {
            this.非特殊挂机分组.IsEnabled = true;
            this.特殊挂机分组.IsEnabled = false;
            this.expander.IsExpanded = false;
            this.expander1.IsExpanded = true;
            this.expander4.IsEnabled = true;
            this.expander7.IsEnabled = true;
            this.包裹监测间隔输入框.IsEnabled = true;
            this.包裹监测间隔标签.IsEnabled = true;
        }

        private void 命令模式_Checked(object sender, RoutedEventArgs e)
        {
            this.号令角色名输入框.IsEnabled = true;
            if (this.号令角色名输入框.Text.Contains("填入"))
            {
                this.号令角色名输入框.Text = "";
            }
            this.号令角色名输入框.Focus();
            this.号令角色名输入框.SelectAll();
        }

        private void 命令模式_Unchecked(object sender, RoutedEventArgs e)
        {
            this.号令角色名输入框.IsEnabled = false;
            if (this.号令角色名输入框.Text == "")
            {
                this.号令角色名输入框.Text = "填入号令角色名";
            }
        }

        private void 定点挂机_Checked(object sender, RoutedEventArgs e)
        {
            this.定点挂机坐标输入框.IsEnabled = true;
            this.定点挂机坐标输入框.Focus();
            this.定点挂机坐标输入框.SelectAll();
        }

        private void 定点挂机_Unchecked(object sender, RoutedEventArgs e)
        {
            this.定点挂机坐标输入框.IsEnabled = false;
        }

        private void 组队设置_Checked(object sender, RoutedEventArgs e)
        {
            this.组队设置输入框.IsEnabled = true;
            if (this.组队设置输入框.Text.Contains("填入"))
            {
                this.组队设置输入框.Text = "";
            }
            this.组队设置输入框.Focus();
            this.组队设置输入框.SelectAll();
        }

        private void 组队设置_Unchecked(object sender, RoutedEventArgs e)
        {
            this.组队设置输入框.IsEnabled = false;
            if (this.组队设置输入框.Text == "")
            {
                this.组队设置输入框.Text = "填入组队成员列表";
            }
        }

        private void 军机任务_Checked(object sender, RoutedEventArgs e)
        {
            this.军机任务分组.IsEnabled = true;
        }
        private void 军机任务_Unchecked(object sender, RoutedEventArgs e)
        {
            this.军机任务分组.IsEnabled = false;
        }

        private void 王城任务_Checked(object sender, RoutedEventArgs e)
        {
            this.王城任务分组.IsEnabled = true;
            this.不领押镖礼盒.IsEnabled = true;
        }

        private void 王城任务_Unchecked(object sender, RoutedEventArgs e)
        {
            this.王城任务分组.IsEnabled = false;
            this.不领押镖礼盒.IsEnabled = false;
        }

        public 挂机人物_ 转为挂机人物(string 配置段键, string 名称, int 序号, bool 模拟器已经启动)
        {
            var 结果 = new 挂机人物_();
            结果.是左侧人物 = 配置段键.Contains('左');
            结果.名称 = 名称;
            结果.启动序号 = 序号;
            结果.模拟器已经启动 = 模拟器已经启动;
            结果.配置段键 = 配置段键;
            结果.姓名 = this.人物名称.Text;
            结果.职业 = this.人物职业.Text;
            结果.等级 = int.Parse(this.人物等级.Text);

            结果.特殊挂机 = this.特殊挂机.IsChecked;

            if (结果.特殊挂机.HasValue && 结果.特殊挂机.Value)
            {
                结果.捡药 = this.捡药.IsChecked;
                结果.买药 = this.买药.IsChecked;

                if (结果.买药.HasValue && 结果.买药.Value)
                {
                    var v = 其他_.尝试编译数字(this.买药输入框.Text);
                    结果.买药库存数量 = v == 0 || v > 9800 ? 9800 : v;
                }

                结果.扔药 = this.扔药.IsChecked;
                if (结果.扔药.HasValue && 结果.扔药.Value)
                {
                    var v = 其他_.尝试编译数字(this.扔药输入框.Text);
                    结果.扔药库存数量 = v == 0 || v > 100 ? 100 : v;
                }

                结果.材料行购买 = this.材料行购买.IsChecked;
                if (结果.材料行购买.HasValue && 结果.材料行购买.Value)
                {
                    结果.材料行购买物品名 = this.材料行购买下拉框.Text;
                }

                结果.命令模式 = this.命令模式.IsChecked;
                if (结果.命令模式.HasValue && 结果.命令模式.Value)
                {
                    结果.号令角色名 = this.号令角色名输入框.Text;
                }
                结果.专打怪物 = this.专打怪物.IsChecked;
                if (结果.专打怪物.HasValue && 结果.专打怪物.Value)
                {
                    var v = this.专打怪物输入框.Text;
                    v = v.Replace(" ", "");
                    结果.专打怪物名列表 = v.Split(new char[] { ',', '，' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                }
                结果.专打boss = this.专打boss.IsChecked;

                if (结果.专打boss.HasValue && 结果.专打boss.Value)
                {
                    var v = this.专打boss输入框.Text;
                    v = v.Replace(" ", "");
                    var vs = v.Split(new char[] { ',', '，' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    结果.专打boss序号 = vs.Select(s => 其他_.尝试编译数字(s)).ToList();
                }
            }
            else
            {
                结果.挂机地图名 = this.挂机地图下拉框.Text;
                结果.定点挂机 = this.定点挂机.IsChecked;
                if (结果.定点挂机.HasValue && 结果.定点挂机.Value)
                {
                    var v = this.定点挂机坐标输入框.Text;
                    if (v == "当前坐标")
                    {
                        结果.定点挂机坐标 = new 坐标_(-1, -1);
                    }
                    else
                    {
                        v = v.Replace(" ", ",");
                        var vs = v.Split(new char[] { ',', '，' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        var x = 其他_.尝试编译数字(vs[0]);
                        var y = 其他_.尝试编译数字(vs[1]);
                        结果.定点挂机坐标 = new 坐标_(x, y);
                    }
                }
                结果.主动攻击 = this.主动攻击.IsChecked;
                结果.主动施毒 = this.主动施毒.IsChecked;
                结果.主动捡物 = this.主动捡物.IsChecked;
                结果.遇人回避 = this.遇人回避.IsChecked;
                结果.Boss优先 = this.Boss优先.IsChecked;
                结果.高级怪物 = this.高级怪物.IsChecked;
                if (结果.高级怪物.HasValue && 结果.高级怪物.Value)
                {
                    var v = this.高级怪物输入框.Text;
                    v = v.Replace(" ", "");
                    结果.高级怪物列表 = v.Split(new char[] { ',', '，' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                }
                结果.组队设置 = this.组队设置.IsChecked;
                if (结果.组队设置.HasValue && 结果.组队设置.Value)
                {
                    var v = this.组队设置输入框.Text;
                    v = v.Replace(" ", "");
                    结果.组队成员列表 = v.Split(new char[] { ',', '，' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    结果.组队任务菜单.成员组 = 结果.组队成员列表;
                }
                结果.军机任务 = this.军机任务.IsChecked;
                if (结果.军机任务.HasValue && 结果.军机任务.Value)
                {
                    结果.指定接受的军机任务 = this.军机任务下拉框.Text;
                }
                结果.王城任务 = this.王城任务.IsChecked;
                结果.不领取拉镖礼盒 = (bool)this.不领押镖礼盒.IsChecked;
                结果.王城诏令 = this.王城诏令.IsChecked;
                结果.声望任务 = this.声望任务.IsChecked;
                结果.骑兵任务 = this.骑兵任务.IsChecked;
                结果.押镖任务 = this.押镖任务.IsChecked;
                结果.挖矿任务 = this.挖矿任务.IsChecked;
                结果.论武任务 = this.论武任务.IsChecked;

                var 购买设置内容 = new List<string>();
                if (this.治疗数量.Text != "")
                {
                    购买设置内容.Add("治疗: " + this.治疗数量.Text);
                }
                if (this.红药数量.Text != "")
                {
                    购买设置内容.Add("红药: " + this.红药数量.Text);
                }
                if (this.蓝药数量.Text != "")
                {
                    购买设置内容.Add("蓝药: " + this.蓝药数量.Text);
                }
                if (this.道符数量.Text != "")
                {
                    购买设置内容.Add("道符: " + this.道符数量.Text);
                }
                if (this.红毒数量.Text != "")
                {
                    购买设置内容.Add("红毒: " + this.红毒数量.Text);
                }
                if (this.绿毒数量.Text != "")
                {
                    购买设置内容.Add("绿毒: " + this.绿毒数量.Text);
                }
                if (this.随机数量.Text != "")
                {
                    购买设置内容.Add("随机: " + this.随机数量.Text);
                }
                if (this.圣水数量.Text != "")
                {
                    购买设置内容.Add("冰泉圣水: " + this.圣水数量.Text);
                }
                结果.购买设置 = new 购买设置_(string.Join(Environment.NewLine, 购买设置内容.ToArray()));
            }

            结果.无需设置 = this.无需设置.IsChecked;
            if (结果.无需设置.HasValue && 结果.无需设置.Value)
            {
                结果.已经初始设置 = true;
            }
            结果.输出日志 = this.输出日志.IsChecked;
            结果.开启录屏 = this.开启录屏.IsChecked;
            结果.包裹监控间隔 = int.Parse(this.包裹监测间隔输入框.Text);
            结果.下线等待时间 = new TimeSpan(0, int.Parse(this.下线等待输入框.Text), 0);

            结果.自动购买炼狱时间 = (bool)this.自动炼狱时间.IsChecked;
            结果.自动购买金币 = this.自动金币.IsChecked;
            结果.二级密码 = this.二级密码.Password;
            结果.技能 = new 技能_(new 技能设置_(this.F1.Text, this.F2.Text, this.F3.Text, this.F4.Text, this.F5.Text, this.F6.Text, this.F7.Text, this.F8.Text));
            return 结果;
        }

        private void 不领礼盒_Checked(object sender, RoutedEventArgs e)
        {
            this.押镖任务.IsChecked = true;
        }

        private void 买药_Checked(object sender, RoutedEventArgs e)
        {
            this.买药输入框.IsEnabled = true;
            if (this.买药输入框.Text.Contains("填入"))
            {
                this.买药输入框.Text = "";
            }
            this.买药输入框.Focus();
            this.买药输入框.SelectAll();
        }

        private void 买药_Unchecked(object sender, RoutedEventArgs e)
        {
            this.买药输入框.IsEnabled = false;
            if (this.买药输入框.Text == "")
            {
                this.买药输入框.Text = "填入买入总数";
            }
        }

        private void 扔药_Checked(object sender, RoutedEventArgs e)
        {
            this.扔药输入框.IsEnabled = true;
            if (this.扔药输入框.Text.Contains("填入"))
            {
                this.扔药输入框.Text = "";
            }
            this.扔药输入框.Focus();
            this.扔药输入框.SelectAll();
        }

        private void 扔药_Unchecked(object sender, RoutedEventArgs e)
        {
            this.扔药输入框.IsEnabled = false;
            if (this.扔药输入框.Text == "")
            {
                this.扔药输入框.Text = "填入扔掉总数";
            }
        }

        private void 材料行购买_Checked(object sender, RoutedEventArgs e)
        {
            this.材料行购买下拉框.IsEnabled = true;
        }

        private void 材料行购买_Unchecked(object sender, RoutedEventArgs e)
        {
            this.材料行购买下拉框.IsEnabled = false;
        }

        private void 专打怪物_Checked(object sender, RoutedEventArgs e)
        {
            this.专打怪物输入框.IsEnabled = true;
            if (this.专打怪物输入框.Text.Contains("填入"))
            {
                this.专打怪物输入框.Text = "";
            }
            this.专打怪物输入框.Focus();
            this.专打怪物输入框.SelectAll();
        }

        private void 专打怪物_Unchecked(object sender, RoutedEventArgs e)
        {
            this.专打怪物输入框.IsEnabled = false;
            if (this.专打怪物输入框.Text == "")
            {
                this.专打怪物输入框.Text = "填入怪物列表";
            }
        }

        private void 专打boss_Checked(object sender, RoutedEventArgs e)
        {
            this.专打boss输入框.IsEnabled = true;

            if (this.专打boss输入框.Text.Contains("填入"))
            {
                this.专打boss输入框.Text = "";
            }
            this.专打boss输入框.Focus();
            this.专打boss输入框.SelectAll();
        }

        private void 专打boss_Unchecked(object sender, RoutedEventArgs e)
        {
            this.专打boss输入框.IsEnabled = false;
            if (this.专打boss输入框.Text == "")
            {
                this.专打boss输入框.Text = "填入BOSS列表序号";
            }
        }

        private void 高级怪物_Checked(object sender, RoutedEventArgs e)
        {
            this.高级怪物输入框.IsEnabled = true;
            if (this.高级怪物输入框.Text.Contains("填入"))
            {
                this.高级怪物输入框.Text = "";
            }
            this.高级怪物输入框.Focus();
            this.高级怪物输入框.SelectAll();
        }

        private void 高级怪物_Unchecked(object sender, RoutedEventArgs e)
        {
            this.高级怪物输入框.IsEnabled = false;
            if (this.高级怪物输入框.Text == "")
            {
                this.高级怪物输入框.Text = "填入组队成员列表";
            }
        }

        private void 挂机人物_左_Checked(object sender, RoutedEventArgs e)
        {
            if (左角色被选择 != null) 左角色被选择(sender, e);
        }

        private void 挂机人物_右_Checked(object sender, RoutedEventArgs e)
        {
            if (右角色被选择 != null) 右角色被选择(sender, e);
        }

        private void 治疗标签_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.治疗数量.Focus();
            this.治疗数量.SelectAll();
        }

        private void 红药标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.红药数量.Focus();
            this.红药数量.SelectAll();
        }

        private void 蓝药标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.蓝药数量.Focus();
            this.蓝药数量.SelectAll();
        }

        private void 道符标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.道符数量.Focus();
            this.道符数量.SelectAll();
        }

        private void 红毒标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.红毒数量.Focus();
            this.红毒数量.SelectAll();
        }

        private void 绿毒标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.绿毒数量.Focus();
            this.绿毒数量.SelectAll();
        }

        private void 随机标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.随机数量.Focus();
            this.随机数量.SelectAll();
        }

        private void 圣水标签_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.圣水数量.Focus();
            this.圣水数量.SelectAll();
        }

    }
}
